//
//  HMStatusToolBarView.swift
//  Weibo
//
//  Created by 吴少飞 on 16/9/23.
//  Copyright © 2016年 wushaofei. All rights reserved.
//

import UIKit

class HMStatusToolBarView: UIView {

    var statusesViewModel : HMStatusesViewModel? {
        didSet{
            
            retweetButton.setTitle(statusesViewModel?.retweetCountContent, for: .normal)
            commentButton.setTitle(statusesViewModel?.commentCountContent, for: .normal)
            unlikeButton.setTitle(statusesViewModel?.unlikeCountContent, for: .normal)
            

        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var retweetButton: UIButton = self.addButton(title: "转发",imageName: "timeline_icon_retweet" )
    private lazy var commentButton: UIButton = self.addButton( title: "评论",imageName: "timeline_icon_comment")
    private lazy var unlikeButton: UIButton = self.addButton(title: "赞",imageName: "timeline_icon_unlike" )

    func setupUI(){
        

        //  设置约束
        retweetButton.snp_makeConstraints { (make) in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) in
            make.top.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
        }
        
        
        let firstLineView = addChildLineView()
        let secondLineView = addChildLineView()
        
        
        firstLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        secondLineView.snp_makeConstraints { (make) in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        

            }
    //创建button
    private func addButton(title:String,imageName:String) -> UIButton {
        
        let  button = UIButton()
        
        button.setTitle(title, for: .normal)
        button.setImage(UIImage(named:imageName), for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), for: .normal)
        //  去掉高亮效果
        button.adjustsImageWhenHighlighted = false
        addSubview(button)
        return button
    }
    // 创建竖线视图
    private func addChildLineView() -> UIImageView {
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }
}
